<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <form id="file" action="/upload" method="POST" enctype="multipart/form-data">
        <input type="file" name="singleFile"/>
        <!-- <input type="button" onclick="uploadFile()" value="上传"/> -->
        <button onclick="uploadFile()">上传图片</button>
    </form>
    <!-- <div id="img"></div> -->
    <script src="jquery-3.6.0min.js"></script>
    <script>
        function uploadFile(){
            var formdata=new FormData($("#file")[0]);
            console.log(formdata);
            $.ajax({
                url:"http://127.0.0.1:8080/upload",
                type:"post",
                data:formdata,
                async:false,
                contentType:false,
                cache:false,
                processData:false,
                success(data){
                    console.log(data);
                    // htmstr="<img src='"+data+"'/>";
                    // $("#img").html(htmstr);
                },
                error(err){
                    console.log(err);
                }
            })
        }
    </script>
</body>
</html>